﻿using MongoDB.Driver;
using SimpleInjector;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.Entities;
using Sustainalytics.Entities.RiskRatings;
using Sustainalytics.MongoDB.Extensions;
using System.Configuration.Abstractions;
using System.Web.Http;

namespace Sustainalytics.RiskRatings.Service
{
    public static class CompositionRoot
    {
        public static Container RegisterDependencies(HttpConfiguration config)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();
            container.RegisterWebApiControllers(config);

            container.RegisterCollections();

            container.Verify();
            return container;
        }

        public static void RegisterCollections(this Container container)
        {
            container.Register(() => MongoFactory.GetConnectionStrings());
            container.Register(() => MongoFactory.GetCollectionFromDatabase<PeerAggregate>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingBenchmark>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingMaterialEsgIssue>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingResearchProfile>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<CoreRiskRatingResearchProfile>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<ComprehensiveRiskRatingIndicator>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<CoreRiskRatingIndicator>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingCluster>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<ExposureCluster>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<ManageableCluster>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<ManagementCluster>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingMeiSubPeerGroupAverage>(db => db.RiskRatingsResearchDW)); 
            container.Register(() => MongoFactory.GetCollectionFromDatabase<Entities.RiskRatings.Incident>(db => db.RiskRatingsResearchDW)); 
            container.Register(() => MongoFactory.GetCollectionFromDatabase<Entities.RiskRatings.EventIndicator>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<GovernancePillars>(db => db.RiskRatingsResearchDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<CorporateData>(db => db.ClientDW));
        }
    }
}
